<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .sonbg1 {
            background-color: lightcoral;
        }

        .sonbg2 {
            background-color: lawngreen;
        }
    </style>
</head>

<body>
    <div id="app">
        <one></one>
        <two></two>
    </div>
</body>

</html>
<script src="./vue.js"></script>
<script>
    //1.事件总线(event-bus)
    const bus = new Vue();
    Vue.component("one", {
        template: `<div class="sonbg1">{{msg}}<button @click="oneMethod">点我改成老二的数据</button></div>`,
        data() {
            return {
                msg: "老大"
            }
        },
        methods: {
            oneMethod() {
                //2.发送数据
                bus.$emit("onefn", "老大给的钱")
            }
        }
    })

    Vue.component("two", {
        template: `<div class='sonbg2'>{{msg}}---{{count}}</div>`,
        data() {
            return {
                msg: "老二",
                count: 1
            }
        },
        mounted() {//生命
            //3.接收数据的那一方
            bus.$on("onefn", (val) => {
                this.count = val
            })
        }
    })




    const vm = new Vue({
        el: "#app",
        data: {},
        methods: {}
    })
</script>